var stepId = $CertusJsonAjax.getStepInstanceId();
var processId = $CertusJsonAjax.getProInstanceId();
$CertusFormAjax.ajax('findWaitInfo',{"processId":processId},function (response) {
    var data = response.data.appInfo;
    $$scope.id = data.id;
    $$scope.tripNum = data.trip_num;
    $$scope.userName = data.user_name;
    $$scope.planStime = data.tripStarTime;
    $$scope.planEtime = data.tripEndTime;
    // $$scope.tripComments = data.trip_comments;
    var bugetInfo = response.data.bugetInfo;
    $$scope.spMoney = 0;
    for (var i=0;i<bugetInfo.length;i++){
        if (bugetInfo[i].status==1){
            $$scope.spMoney = bugetInfo[i].buget;
        }
    }
    $$scope.actualAplStarTime = data.actualTripTime;
    $$scope.actualAplEndTime = data.actualEndTime;
    if(data.type==1){
        $$scope.type ="出差";
    }else{
        $$scope.type ="公干";
    }
});

//查询审批人职位
$CertusFormAjax.ajax('getSpPosition',{},function (response) {
    var data = response.data;
    $$scope.position = data;
});

$CertusFormAjax.ajax('findForceBuget',{"processId":processId},function (response) {
    var data = response.data;
    $$scope.bugets = data;
});
$CertusFormAjax.ajax('findTripPlans',{"processId":processId},function (response) {
    var data = response.data;
    for (var i=0;i<data.length;i++){
        $$scope.appid = data[i].id;
    }
    proInfo();
});

function proInfo() {
    $CertusFormAjax.ajax('findLastPlan',{"tripId":processId},function (response) {
        var data = response.data;
        $$scope.sproId = data.proId;
        $$scope.sproName = data.projName;
        $$scope.splanStarTime = data.planStarTime;
        $$scope.splanEndTime = data.planEndTime;
        $$scope.splanCity = data.planCity;
        $$scope.splanComments = data.planComments;
        $$scope.aid = data.id;
        // $$scope.actualStarTime = data.actualStarTime;
        // $$scope.actualEndTime = data.actualEndTime;
        $$scope.tripResult = data.tripResult;
    });
}

//取消申请
$(".down").on('click',function () {
    $CertusFormAjax.ajax('shutdownWait',{"id":$$scope.id,"stepId":stepId,"processId":processId},function (response) {
        layer.msg("取消成功！");
        window.history.back();
    });
});
//提交申请
$(".submitTrip").on('click',function () {
    var starTime = $("#startTime").val();
    var endTime = $("#endTime").val();
    var planResult = $("#planResult").val();
    if (starTime==""){
        layer.msg("实际计划开始时间不能为空");
        return;
    }
    if (endTime==""){
        layer.msg("实际计划结束时间不能为空");
        return;
    }
    var sdate = new Date(starTime);
    var edate = new Date(endTime);
    if (Date.parse(sdate) > Date.parse(edate)) {
        layer.msg("开始时间不能大于结束时间！");
        return;
    }

    if (planResult.trim()==""){
        layer.msg("工作结果不能为空");
        return;
    }
    $CertusFormAjax.ajax('writeSingleActResult',{"id":$$scope.id,"stepId":stepId,
        "processId":processId,"starTime":starTime,
    "endTime":endTime,"planResult":planResult,"planId":$$scope.aid},function () {
        layer.msg("提交成功！");
        window.history.back();
    });
});